﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Nirvana
{
    public class WaitLoadObjectSync : WaitLoadObject
    {
        private string assetpath;
        private string bundlename;
        private Type assettype;
        private UnityEngine.Object assetObj;
        private AssetBundleManager abMgr;
        public AssetBundleManager AssetBundleMgr
        {
            get { return abMgr; }
            set { abMgr = value; }
        }

        public string AssetPath
        {
            get { return assetpath; }
        }
       
        public WaitLoadObjectSync(AssetBundleManager mgr, string path, string bundlename, Type abtype)
        {
            abMgr = mgr;
            assetpath = path;
            this.bundlename = bundlename;
            assettype = abtype;
        }

        public override bool keepWaiting
        {
            get
            {
                return base.Error == null && this.assetObj == null;
            }
        }

        public override UnityEngine.Object GetObject()
        {
            return this.assetObj;
        }

        public override bool Load()
        {
            AssetBundleItem item = this.abMgr.LoadAssetBundleItem(this.assetpath);
            if (item == null) return true;
            if (!string.IsNullOrEmpty(item.error))
            {
                base.Error = item.error;
                return false;
            }
            this.assetObj = item.assetbundle.LoadAsset(this.bundlename, this.assettype);
            return false;
        }
    }
}

